package com.houweishi.module.type.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.type.domain.BizApprovalType;
import com.houweishi.module.type.service.IBizApprovalTypeService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 审批模板Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/type")
public class BizApprovalTypeController extends BaseController
{
    @Autowired
    private IBizApprovalTypeService bizApprovalTypeService;

    /**
     * 查询审批模板列表
     */
    @PreAuthorize("@ss.hasPermi('module:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizApprovalType bizApprovalType)
    {
        startPage();
        List<BizApprovalType> list = bizApprovalTypeService.selectBizApprovalTypeList(bizApprovalType);
        return getDataTable(list);
    }

    /**
     * 导出审批模板列表
     */
    @PreAuthorize("@ss.hasPermi('module:type:export')")
    @Log(title = "审批模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizApprovalType bizApprovalType)
    {
        List<BizApprovalType> list = bizApprovalTypeService.selectBizApprovalTypeList(bizApprovalType);
        ExcelUtil<BizApprovalType> util = new ExcelUtil<BizApprovalType>(BizApprovalType.class);
        util.exportExcel(response, list, "审批模板数据");
    }

    /**
     * 获取审批模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizApprovalTypeService.selectBizApprovalTypeById(id));
    }

    /**
     * 新增审批模板
     */
    @PreAuthorize("@ss.hasPermi('module:type:add')")
    @Log(title = "审批模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizApprovalType bizApprovalType)
    {
        return toAjax(bizApprovalTypeService.insertBizApprovalType(bizApprovalType));
    }

    /**
     * 修改审批模板
     */
    @PreAuthorize("@ss.hasPermi('module:type:edit')")
    @Log(title = "审批模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizApprovalType bizApprovalType)
    {
        return toAjax(bizApprovalTypeService.updateBizApprovalType(bizApprovalType));
    }

    /**
     * 删除审批模板
     */
    @PreAuthorize("@ss.hasPermi('module:type:remove')")
    @Log(title = "审批模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizApprovalTypeService.deleteBizApprovalTypeByIds(ids));
    }
}
